﻿@using JD.Invoicing.Web.Models.Common.Modals
@model JD.Invoicing.Web.Models.Roles.EditRoleModalViewModel
@{
    Layout = null;
}
@Html.Partial("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("EditRole")))

<div class="modal-body">
    <form name="RoleEditForm" role="form" novalidate class="form-validation">
        <input type="hidden" name="Id" value="@Model.Role.Id" />
        <input type="hidden" name="IsStatic" value="@(Model.Role.IsStatic.ToString())" />
        <ul class="nav nav-tabs tab-nav-right" role="tablist">
            <li role="presentation" class="active"><a href="#edit-role-details" data-toggle="tab">@L("RoleDetails")</a></li>
            <li role="presentation"><a href="#edit-role-permissions" data-toggle="tab">@L("RolePermissions")</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane animated fadeIn active" id="edit-role-details">
                <div class="row clearfix">
                    <div class="col-sm-12">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input id="rolename" @(Model.Role.IsStatic ? "disabled" : "") type="text" name="Name" value="@Model.Role.Name" required maxlength="32" minlength="2" class="validate form-control">
                                <label for="rolename" class="form-label">@L("RoleName")</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-12">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input id="displayname" type="text" name="DisplayName" value="@Model.Role.DisplayName" required maxlength="32" minlength="2" class="validate form-control">
                                <label for="displayname" class="form-label">@L("DisplayName")</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea id="role-description" name="Description" class="validate form-control">@Model.Role.Description</textarea>
                                <label for="role-description" class="form-label">@L("RoleDescription")</label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane animated fadeIn" id="edit-role-permissions">

                <div class="row clearfix">
                    <div class="col-sm-12">
                        @foreach (var permission1 in Model.Permissions)
                        {
                            if (permission1.ParentID == 0)
                            {
                                <div class="col-sm-12">
                                    <hr />
                                    @if (permission1.Name.StartsWith("Pages"))
                                    {
                                        <input type="checkbox" name="permission" value="@permission1.Name" class="filled-in" id="permission-@permission1.Name" />
                                    }
                                    <label for="permission-@permission1.Name">@L(permission1.DisplayName)</label>
                                    <hr />
                                </div>
                                @foreach (var permission2 in Model.Permissions)
                                {
                                    if (permission2.ParentID == permission1.Id)
                                    {
                                    <div class="col-sm-12">
                                        @if (permission2.Name.StartsWith("Pages"))
                                        {
                                        <input type="checkbox" name="permission" value="@permission2.Name" class="filled-in" id="@string.Format("permission{0}",permission2.Name)" @(Model.HasPermission(permission2) ? "checked" : "") @(Model.Role.IsStatic ? "disabled" : "") />
                                        } 
                                        <label for="@string.Format("permission{0}",permission2.Name)">@L(permission2.DisplayName)</label>
                                    </div>
                                        @foreach (var permission3 in Model.Permissions)
                                        {
                                            if (permission3.ParentID == permission2.Id)
                                            {
                                            <div class="col-sm-12">
                                                @if (permission3.Name.StartsWith("Pages"))
                                                {
                                                <input type="checkbox" name="permission" value="@permission3.Name" class="filled-in" id="@string.Format("permission{0}",permission3.Name)" @(Model.HasPermission(permission3) ? "checked" : "") @(Model.Role.IsStatic ? "disabled" : "") />
                                                }
                                                <label for="@string.Format("permission{0}",permission3.Name)">@L(permission3.DisplayName)</label>
                                            </div>
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

@Html.Partial("~/Views/Shared/Modals/_ModalFooterWithSaveAndCancel.cshtml")

<script src="~/view-resources/Views/Roles/_EditRoleModal.js" asp-append-version="true"></script>
